<template>
  <div id="app">
    <h1>自定义指令</h1>
    <input type="text" v-focus />
    <h1 v-color="color1">指令的值1测试</h1>
    <h1 v-color="color2">指令的值2测试</h1>
  </div>
</template>

<script>

export default {
  name: "App",
  components: {},
  data() {
    return {
      defaultMsg: "这是一个默认文本",
      color1: "red",
      color2: "green",
    };
  },
  methods: {
    handleChange() {
      console.log(this.defaultMsg);
    },
  },
  directives: {
    focus: {
      inserted(el) {
        el.focus();
        console.log("这是一个自定义局部指令", el);
      },
    },
    color: {
      inserted(el,binding) { 
        console.log(el);
        el.style.color = binding.value
      },
    },
  },
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;

  background: yellow;
  border: solid 1px black;
}
</style>
